//
//  AppDelegate.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/10/21.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import Alamofire

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    let manager = NetworkReachabilityManager(host: "www.baidu.com")
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
                        
        let keyboardManager = IQKeyboardManager.shared()
        keyboardManager.shouldResignOnTouchOutside = true
        keyboardManager.isEnableAutoToolbar = true
        
        window = UIWindow.init(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        
        let userModel = TSLoginManager.shared.getUserModel()
        if userModel != nil {
            TSLoginManager.shared.token = userModel!.token
            TSLoginManager.shared.user_id = userModel!.user_id
            window?.rootViewController = TSTabbarController()
        } else {
            window?.rootViewController = TSLoginViewController()
        }

//        startNetworkMinitor()
        
        return true
    }
    
    private func startNetworkMinitor() {
        
        manager!.listener = { status in
            
            switch status {
            case .notReachable,.unknown:
                CBToast.showToast(message: "网络连接中断", aLocationStr: "center", aShowTime: 2)
                print("notReachable")
            case .reachable(.ethernetOrWiFi):
                print("ethernetOrWiFi")
            case .reachable(.wwan):
                print("wwan")
                
            }
        }
        manager!.startListening()
        
    }

}

